package com.util.theMSG;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class SMSUtil {
    private String addr = "http://api.sms.cn/sms/";

    private String userId = "aidan200";

    private String pwd = "b7298cb8d99836a32c9c4ffe596bd142";

    private String econd = "utf8";

    public void send(String msgContent, String mobile ,String template) throws Exception {
        //组建请求
        String straddr = addr +
                "?ac=send&uid="+userId+
                "&pwd="+pwd+
                "&mobile="+mobile+
                "&content=" + msgContent+
                "&econd=" + econd;
        //"&template=" + template;

        StringBuffer sb = new StringBuffer(straddr);
        System.out.println("URL:"+sb);

//发送请求
        URL url = new URL(sb.toString());
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        BufferedReader in = new BufferedReader(new InputStreamReader(
                url.openStream()));

//返回结果
        String inputline = in.readLine();
        System.out.println("Response:"+inputline);

    }
}
